package com.ncloud.act.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ncloud.act.entity.AccountDeposit;

@Mapper
public interface AccountDepositMapper{

	@Select("SELECT acct_balance_id, acct_id, deposit_code, deposit_money, init_money, invoice_money, print_money,"
			+ "date_format(begin_time, '%Y-%m-%d %H:%i:%s' ) as begin_time, date_format(end_time, '%Y-%m-%d %H:%i:%s' ) as end_time, "
			+ "valid_tag, freeze_money, project_id, contract_inst_id, date_format(update_time, '%Y-%m-%d %H:%i:%s' ) as update_time, "
			+ "update_user_id, rsrv_money1, rsrv_info1, remark "
			+ "FROM bi_d_accountdeposit where acct_id =#{acctID} "
			+ "and (valid_tag=1 or now() between begin_time and end_time)")
	@Results({
		@Result(column="acct_balance_id",property="acct_balance_id"),@Result(column="acct_id",property="acct_id"),
		@Result(column="deposit_code",property="deposit_code"),@Result(column="deposit_money",property="deposit_money"),
		@Result(column="init_money",property="init_money"),@Result(column="invoice_money",property="invoice_money"),
		@Result(column="print_money",property="print_money"),@Result(column="begin_time",property="begin_time"),
		@Result(column="end_time",property="end_time"),@Result(column="valid_tag",property="valid_tag"),
		@Result(column="freeze_money",property="freeze_money"),@Result(column="project_id",property="project_id"),
		@Result(column="contract_inst_id",property="contract_inst_id"),@Result(column="update_time",property="update_time"),
		@Result(column="update_user_id",property="update_user_id"),@Result(column="rsrv_money1",property="rsrv_money1"),
		@Result(column="rsrv_info1",property="rsrv_info1"),@Result(column="remark",property="remark")})
	List<AccountDeposit> getAccountDepositByAcctID(Long acctID);
	
	//@Transactional(propagation=Propagation.REQUIRED)
	@Insert(value = "insert into bi_d_accountdeposit(acct_balance_id, acct_id, deposit_code, deposit_money, init_money, invoice_money, print_money, begin_time, end_time, valid_tag, freeze_money, project_id, contract_inst_id, update_time, update_user_id, rsrv_money1, rsrv_info1, remark) "
			+ "values(#{acct_balance_id},#{acct_id},#{deposit_code},#{deposit_money},#{init_money},#{invoice_money},#{print_money},#{begin_time},#{end_time},#{valid_tag},#{freeze_money},#{project_id},#{contract_inst_id},#{update_time},#{update_user_id},#{rsrv_money1},#{rsrv_info1},#{remark})")
    public int insertAccountDeposit(AccountDeposit accountDeposit);
	
	@Update(value = "UPDATE bi_d_accountdeposit SET deposit_money = #{deposit_money}, invoice_money = #{invoice_money},update_time = #{update_time}, update_user_id = #{update_user_id} WHERE acct_balance_id = #{acct_balance_id} ")
    public int updateAccountDeposit(AccountDeposit accountDeposit);
}
